import { Message } from 'element-ui'
export const state = () => ({
    userInfo: {}
})

export const actions = {
    async userLogin({ commit }, userInfo) {
        try {
            const { data: res } = await this.$userLogin(userInfo)
            if (res.code !== '1') return Message.error(res.message)
            commit('userLogin', res.result)
        } catch (error) {
            return {
                status: false,
                message: error.message
            }
        }
    }
}
export const mutations = {
    // 登录
    userLogin(state, userInfo) {
        state.userInfo = userInfo
        this.$cookies.set('userInfo', userInfo)
    },
    // 查看用户数据
    getUserInfo(state) {
        state.userInfo = this.$cookies.get('userInfo')
    },
    // 清除用户数据
    clearUserInfo(state) {
        state.userInfo = {}
        this.$cookies.remove('userInfo')
    }
}